#遍历文件夹 将两个文件夹的图像进行叠加
import os
import cv2
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image


length = len(os.listdir(r"E:\pose\datasets\linemod\LINEMOD\objects\target\rgb"))
if not os.path.exists(r"E:\pose\datasets\linemod\LINEMOD\objects\target\rgb_mask"):
    os.makedirs(r"E:\pose\datasets\linemod\LINEMOD\objects\target\rgb_mask")
for i in range(length):
    img1 = cv2.imread(r"E:\pose\datasets\linemod\LINEMOD\objects\target\rgb" + f"\{i:06d}" + ".png")
    img2 = cv2.imread(r"E:\pose\datasets\linemod\LINEMOD\objects\target\mask" + f"\{i}" + ".png")
    print(img1.shape)
    print(img2.shape)
    img = cv2.addWeighted(img1, 0.5, img2, 0.5, 0)
    cv2.imwrite(r"E:\pose\datasets\linemod\LINEMOD\objects\target\rgb_mask" + f"\{i:06d}" + ".png", img)
    print(f"{i} image has been processed")